<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>U8檢查首爾標籤</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">	
    <link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen">
    <link rel="stylesheet" href="./_assets/css/custom.min.css">
  </head>
  <body>
  <div class="container" style='position:fixed; left:30px; top:30px;'>
	<form id="myform">
	  <fieldset>
		<h5>U8檢查首爾標籤</h5>
		<!--button type="button" id="btnNext" class="btn btn-primary">下一箱</button-->
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">目前箱號:</label>
		  <div class="col-sm-10">
		  <input class="form-control" placeholder="17620T4003-7250613" id="box" type="text">
		  </div>
		</div>	

		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">目前卷盤:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="17619T8083-7250613" id="diskNow" type="text">
		  </div>
		  <div class="col-sm-2">
		   <input readonly="" class="form-control-plaintext" id="msg" value="" type="text">
		  </div>
		</div>	
		
		
		<div class="row">
			<div class="col-md-12">
				<table class="table table-hover" id="dats_table">
					<thead>
						
				 	</thead>
				 	<tbody>
						
				 	</tbody>
				</table>
			</div>
		</div>
	
	</form>	
	<p class="lead">
    <a class="btn btn-primary btn-lg" href="index.html" role="button">返回</a>
	</p>
	</div>
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	<script>
	var disks;
	var cksA=0;
	var cksB=0;
	var Length;
	var cks=new Array(4);
		$("#box").keypress(function(e){    //
		  console.log($("#box").val());
		$("#dats_table tbody").empty();//清空表单内容
		  var key = e.which;
		  if (key == 13) { 
			$.ajax({ url: "getDisk.php?lot="+$("#box").val(), 
					dataType : "text",
					success: function(data){
						
						console.log(data);
						disks=data.split(",");
						Length  = disks.length-1;
						if(Length%2==0){
						for(i=0;i<Length;i=i+2){//一行放两个卷盘
									var disk = $("<td id='"+'d_sign'+i+"'></td>").append("卷盘"+(i+1));
									var idTd = $("<td id='"+'d'+i+"'></td>").append(disks[i]);
									var disk1 = $("<td></td>").append("卷盘"+(i+2));
									var idTd1 = $("<td id='"+'d'+(i+1)+"'></td>").append(disks[i+1]);
									cksA=cksA+i+1;
									cksA=cksA+i+2;
									$("<tr></tr>")
									.append(disk).append(idTd).append(disk1).append(idTd1)
									.appendTo("#dats_table tbody"); 
									cks[i]="N";
									cks[i+1]="N";
							}
						}
						if(Length%2==1){
							for(i=0;i<Length-1;i=i+2){
									var disk = $("<td id='"+'d_sign'+i+"'></td>").append("卷盘"+(i+1));
									var idTd = $("<td id='"+'d'+i+"'></td>").append(disks[i]);
									var disk1 = $("<td></td>").append("卷盘"+(i+2));
									var idTd1 = $("<td id='"+'d'+(i+1)+"'></td>").append(disks[i+1]);
									cksA=cksA+i+1;
									cksA=cksA+i+2;
									$("<tr></tr>")
									.append(disk).append(idTd).append(disk1).append(idTd1)
									.appendTo("#dats_table tbody"); 
									cks[i]="N";
									cks[i+1]="N";
								
							}
							
								var disk = $("<td></td>").append("卷盘"+(Length));
								var idTd = $("<td id='"+'d'+i+"'></td>").append(disks[Length-1]);
								
								cksA=cksA+i+1;
								
								$("<tr></tr>")
								.append(disk).append(idTd)
								.appendTo("#dats_table tbody"); 
								cks[i]="N";
								
						}
					  }
				  });		  
		  
			$( "#diskNow" ).focus();
		 }
		});	
		
		$("#diskNow").keypress(function(e){
		  
	
		  dk=$("#diskNow").val();
		  var key = e.which;
		  var ss;
		  
			if (key == 13){
				$(msg).val("");
					
					//data[data.length]="";
					for(ss=0;ss<Length;ss++){
					var id="d"+ss;
					var keys=document.getElementById(id).innerHTML;
					console.log(dk);
					var dks= dk.split("-");
					var keyss=keys.split("-");
					if(dk==keys){//外箱键盘与内箱卷盘就行匹配,如果匹配不上可能以前的
						//$("#d"+ss).css('color', 'green');              存货编码不一样就对其进行拆分（头尾）比较
						if(cks[ss]!='Y'){
							cksB=cksB+ss+1;
							cks[ss]='Y' ;
						}
						
						$("#diskNow").select();
						$("#d"+ss).css('color', 'green');
						if(cksA==cksB){
							$("#box").select();
							$(msg).val("");
							
						}
						
						$(msg).val("驗證通過").css('color', 'green');
						break;
					}
					else{
						$(msg).val("驗證失敗").css('color', 'red');
						$("#diskNow").select();
					}
				}
					
				
			}
		});	
	
	</script>
	
	
  </body>
</html>
